Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary support #218

Merged
merged 9 commits into from Feb 19, 2014
Merged

Binary support #218

merged 9 commits into from Feb 19, 2014

Conversation

rase-
Copy link
Contributor

@rase- rase- commented Feb 1, 2014

This pull request answers issue #182 of sending binary data over engine.io. This issue involves also engine.io-client and engine.io-protocol. The work is still a bit ongoing, but I'd like to know what you guys think. This is my first OSS pull request, so be gentle. ;)

With these changes binary data can be sent from the server to the client, and the other way around. The API for sending binary data is the same as for sending utf-8 strings, but binary types are detected. When a client on a browser calls socket.send for an ArrayBuffer, or an ArrayBufferView the data is sent as binary. For a node server the possibilities are the aforementioned, and also Buffer. The data is then received as binary on the other end. For details on how data is received on clients, consult the engine.io-client pull request. The server always receives all binary data as a Buffer, which is the type of the message in on('message', fn).

Binary data can be sent over all transports. For XHR polling the default setting is using responseType of XHR2 to deliver binary data directly. The engine.io client notifies the server for the possibly missing XHR2 support, so that the server knows whether to encode binary data as strings, or send them as binary. In the case of string encoding, the binary data is encoded into a base64 string. Base64 encoding is the default option for FlashSockets and JSONP polling. WebSockets have their own support for binary data. For more information on how the encoding happens, consult the engine.io-protocol pull request.

@rase-
Copy link
Contributor Author

rase- commented Feb 1, 2014

engine.io-protocol pull request: socketio/engine.io-protocol#15
engine-client pull request: socketio/engine.io-client#244

@@ -60,7 +61,10 @@ httpServer.on('request', function (req, res) {
<script src="/path/to/engine.io.js"></script>
<script>
var socket = new eio.Socket('ws://localhost/');
// by default binary type is: socket.binaryType = 'arraybuffer'
socket.binaryType = 'blob';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be in its own dedicated example as to avoid confusion with the typical usecase

@rase-
Copy link
Contributor Author

rase- commented Feb 1, 2014

Thanks for the great comments. I'll make the convention changes. Also I completely agree about doing the detection for encoding binary data in the parser. There is no Blob or BlobBuilder in Node is there? It should, however, be possible to send those from a browser client (which in the current implementation is not possible).

* @api public
*/

XHR.prototype.supportsBinary = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not always the case, as in ActiveXObject. Why is this always true ?

@rase-
Copy link
Contributor Author

rase- commented Feb 18, 2014

Thanks for the great comments again. I'll make the style changes. Hmm yes, that value put to the prototype is just a default value, which is set to false in handshaking if needed. I should change that to not be set in the prototype at all.

rauchg added a commit that referenced this pull request Feb 19, 2014
@rauchg rauchg merged commit ab4ea94 into socketio:master Feb 19, 2014
laino pushed a commit to laino/engine.io that referenced this pull request Jun 19, 2015
darrachequesne pushed a commit that referenced this pull request May 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants